package com.jiang.myfm.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiang.myfm.R;
import com.jiang.myfm.entities.mianpage.ListSpecialColumn;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dell on 2016/12/9 0009.
 */
public class MainRecyclerAdapterSpecial extends RecyclerView.Adapter<MainRecyclerAdapterSpecial.ViewHolder>{
    private List<ListSpecialColumn> mMainRecyclerSpecialDataList;
    private Context context;

    public MainRecyclerAdapterSpecial(List<ListSpecialColumn> mainRecyclerSpecialDataList, Context context) {
        mMainRecyclerSpecialDataList = mainRecyclerSpecialDataList;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_main_recycler_two, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Picasso.with(context).load(mMainRecyclerSpecialDataList.get(position).getCoverPath()).into(holder.mImageView);
        holder.mTextViewTitle.setText(mMainRecyclerSpecialDataList.get(position).getTitle());
        holder.mTextViewSubTitle.setText(mMainRecyclerSpecialDataList.get(position).getSubtitle());
        holder.mTextViewFootnote.setText(mMainRecyclerSpecialDataList.get(position).getFootnote());
    }

    @Override
    public int getItemCount() {
        return mMainRecyclerSpecialDataList != null ? mMainRecyclerSpecialDataList.size() : 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private ImageView mImageView;
        private TextView mTextViewSubTitle, mTextViewTitle,mTextViewFootnote;

        public ViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.list_item_main_recycler_two_iv);
            mTextViewTitle = (TextView) itemView.findViewById(R.id.list_item_main_recycler_two_tv1);
            mTextViewSubTitle = (TextView) itemView.findViewById(R.id.list_item_main_recycler_two_tv2);
            mTextViewFootnote = (TextView) itemView.findViewById(R.id.list_item_main_recycler_two_tv3);
        }
    }

    public void addAll(List<ListSpecialColumn> list) {
        mMainRecyclerSpecialDataList.addAll(list);
        notifyDataSetChanged();
    }
}
